package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"house/house"
	"house/houseclient"
	"house/internal/svc"
	"house/models"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源列表
func (l *HouseListLogic) HouseList(in *house.HouseListReq) (*house.HouseListResp, error) {
	// todo: 房源列表
	var h models.House
	list := h.FindHouse(int(in.HouseId), int(in.Page), int(in.Size))
	var lists []*house.HouseList
	for _, v := range list {
		lists = append(lists, &houseclient.HouseList{
			City:    v.City,
			Address: v.Address,
			Floor:   v.Floor,
			Size:    float32(v.Size),
			Price:   int64(v.Price),
			Info:    v.Info,
			Status:  int64(v.Status),
			UserId:  int64(v.UserId),
		})
	}

	return &house.HouseListResp{
		List: lists,
	}, nil
}
